package com.tisson.action;

import java.util.ArrayList;
import java.util.List;

import com.tisson.bo.PurviewBO;
import com.tisson.comment.WebConstants;
import com.tisson.pojo.Page;

public class PageAction extends ActionSup{
	
	private List result = new ArrayList();
	private List infoList = new ArrayList();
	private Page page;
	private String userId;
	private List areaList;
	private List districtList = new ArrayList();
	private List buildingList = new ArrayList();
	private List doorList = new ArrayList();
	private String areaId;
	private String buildingId;
	private String districtId;

	
	public String changePage(){
		int point =0;
		List list = (List)request.getSession().getAttribute("list");
		int requestPage = Integer.parseInt(request.getParameter("requestPage"));
		String mapping = request.getParameter("map");
		page = new Page();
		final int totalPages = list.size()%WebConstants.PAGESIZE==0?list.size()/WebConstants.PAGESIZE:list.size()/WebConstants.PAGESIZE+1;
		if(requestPage<1){
			page.setCurrentPage(1);
		}
		else if(requestPage>totalPages){
			page.setCurrentPage(totalPages);
		}
		else{
			page.setCurrentPage(requestPage);
		}
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(list.size());
		page.setTotalPages(totalPages);
		final int begin = (page.getCurrentPage()-1)*WebConstants.PAGESIZE;
		final int end = begin+WebConstants.PAGESIZE;
		if(end>list.size()-begin)
			point = list.size();
		else
			point = end;
			
		try{
			for(int i=begin;i<point;i++){
				result.add(list.get(i));
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}

		PurviewBO bo =  new PurviewBO();	
		areaList = bo.getOptionArea(request);
		districtList = bo.getOptionDistrict(request.getParameter("areaId"));
		buildingList = bo.getOptionBuilding(request.getParameter("districtId"));
		doorList = bo.getOptionDoor(request.getParameter("buildingId"));
		this.setAreaId(areaId);
		this.setDistrictId(districtId);
		this.setBuildingId(buildingId);
		return mapping;
	}



	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List getInfoList() {
		return infoList;
	}

	public void setInfoList(List infoList) {
		this.infoList = infoList;
	}

	public List getAreaList() {
		return areaList;
	}

	public void setAreaList(List areaList) {
		this.areaList = areaList;
	}

	public List getDistrictList() {
		return districtList;
	}

	public void setDistrictList(List districtList) {
		this.districtList = districtList;
	}

	public List getBuildingList() {
		return buildingList;
	}

	public void setBuildingList(List buildingList) {
		this.buildingList = buildingList;
	}

	public List getDoorList() {
		return doorList;
	}

	public void setDoorList(List doorList) {
		this.doorList = doorList;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getBuildingId() {
		return buildingId;
	}

	public void setBuildingId(String buildingId) {
		this.buildingId = buildingId;
	}

	public String getDistrictId() {
		return districtId;
	}

	public void setDistrictId(String districtId) {
		this.districtId = districtId;
	}
	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

}
